<?php
/**
 * Created by PhpStrom
 * User: 魏惠东
 * Date: 2021/6/2 15:09
 * Desc:
 */

namespace App\Models\Admin;
use App\Models\BaseModel;

class Post extends BaseModel{
    protected $table = "post";
    protected $casts = [
        'created_at' => 'datetime:Y-m-d H:i:s',
        'updated_at' => 'datetime:Y-m-d H:i:s'
    ];

    protected $fillable=["name","sort","group_id","site_id","creator"];
    /**
     * 列表
     * @param $search 条件数组
     */
    public static function getList($limit,$search){
        return self::
            leftJoin('post_group as g','post.group_id','g.id')
            ->select('post.*','g.name as group_name')
            ->where(function($query) use ($search){
                if(!empty($search['keyword'])){
                    $query->where("name","like","%".$search['keyword']."%");
                }
                if(!empty($search['group_id'])){
                    $query->where("group_id",$search['group_id']);
                }
            })->orderBy('sort','asc')->orderBy('id','desc')->paginate($limit)->toArray();
    }

    public static function selectData($where){
        return self::where($where)->get();
    }
}
